package org.pgis.gui;

import javax.swing.JPanel;
import javax.swing.JLabel;

import org.pgis.core.AbstractScenePanel;

import java.awt.Font;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class LightPanel extends JPanel{

	private static final long serialVersionUID = 1L;
	private AbstractScenePanel asp;

	public LightPanel(AbstractScenePanel asp) {
		this.asp = asp;
		initialize();
	}

	private void initialize() {

		this.setLayout(null);

		JLabel labelLight = new JLabel("Lighting");
		labelLight.setFont(new Font("Century", Font.BOLD, 16));
		labelLight.setBounds(79, 6, 117, 30);
		this.add(labelLight);

		JSlider sliderAmbient = new JSlider();
		sliderAmbient.setPaintLabels(true);
		sliderAmbient.setPaintTicks(true);
		sliderAmbient.setValue((int)asp.getSim().getActor().GetProperty().GetOpacity() * 10);
		System.out.println((int)asp.getSim().getActor().GetProperty().GetOpacity() * 10);
		sliderAmbient.setMaximum(10);
		sliderAmbient.setBounds(14, 78, 231, 21);
		sliderAmbient.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setAmbient(value);
                asp.refresh();
            }
        });
		add(sliderAmbient);

		JLabel lblAmbient = new JLabel("Ambient");
		lblAmbient.setFont(new Font("SansSerif", Font.BOLD, 13));
		lblAmbient.setBounds(14, 50, 72, 16);

		add(lblAmbient);

		JLabel lblDiffuse = new JLabel("Diffuse");
		lblDiffuse.setFont(new Font("SansSerif", Font.BOLD, 13));
		lblDiffuse.setBounds(14, 107, 72, 16);
		add(lblDiffuse);

		JSlider sliderDiffuse = new JSlider();
		sliderDiffuse.setValue(0);
		sliderDiffuse.setPaintTicks(true);
		sliderDiffuse.setPaintLabels(true);
		sliderDiffuse.setMaximum(10);
		sliderDiffuse.setBounds(14, 136, 231, 21);
		sliderDiffuse.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setDiffuce(value);
                asp.refresh();
            }
        });

		add(sliderDiffuse);

		JLabel lableSpecular = new JLabel("Specular");
		lableSpecular.setFont(new Font("SansSerif", Font.BOLD, 13));
		lableSpecular.setBounds(14, 169, 72, 16);
		add(lableSpecular);

		JSlider sliderSpecular = new JSlider();
		sliderSpecular.setValue(0);
		sliderSpecular.setPaintTicks(true);
		sliderSpecular.setPaintLabels(true);
		sliderSpecular.setMaximum(10);
		sliderSpecular.setBounds(14, 197, 231, 21);
		sliderSpecular.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setSpecular(value);
                asp.refresh();
            }
        });
		add(sliderSpecular);
	}
}
